var id=1;
option = {};
configs = {};
var clickbutton="bar_status";
default1 = {
    timeout: 15000,
    sid: '00000000000000000000000000000000',
    isLogin: false
};

var barpara= new Array('status1','net_setup','wifi_setup','hulian_setup','pass_setup','serial_setup','simulate_setup','directconnect_setup');
function show(data) {
    for (var key1 in barpara) {
        if(data==barpara[key1]) {
            document.getElementById(barpara[key1]).style.display="block";
        }else {
            document.getElementById(barpara[key1]).style.display = "none";
        }
    }
}
function showstatus(){
    show("status1");
    option = default1;
    onReadre.init();
}
function showsetup(){
    show("net_setup");

   // $("#lan_ip1").html(configs.lan.ipaddr);

    document.getElementById("lan_ip1").value=configs.lan.ipaddr;


    if("undefined"!=typeof (configs.wanStauts) )
    {
        if(configs.wanStauts.proto=="dhcp")
        {
            document.getElementById("wan_proto").options[1].selected="true";
            document.getElementById("static_status").style.display="none";
            document.getElementById("pppoe_status").style.display="none";
        }

        if(configs.wanStauts.proto=="static")
        {
            document.getElementById("wan_proto").options[0].selected="true";
            document.getElementById("static_status").style.display="block";
            document.getElementById("pppoe_status").style.display="none";

            $("#wan_static_ip").val(configs.wanStauts.ipaddr);
            $("#wan_static_mask").val(configs.wanStauts.netmask);
            $("#wan_static_gateway").val(configs.wanStauts.gateway);
            if(configs.wanStauts.dns[0]!="null") {
                $("#wan_static_dns1").val(configs.wanStauts.dns[0]);
            }else{$("#wan_static_dns1").val("");}
            if(configs.wanStauts.dns[1]!="null") {
                $("#wan_static_dns2").val(configs.wanStauts.dns[1]);
            }else{$("#wan_static_dns2").val("");}
        }
        if( configs.wanStauts.proto=="pppoe")
        {
            document.getElementById("static_status").style.display="none";
            document.getElementById("pppoe_status").style.display="block";

            document.getElementById("wan_proto").options[2].selected="true";

            if(configs.wan.username!="null") {
                $("#pppoe_user").val(configs.wan.username);
            }else{$("#pppoe_user").val("");}
            if(configs.wan.password!="null") {
                $("#pppoe_pass").val(configs.wan.password);
            }else{$("#pppoe_pass").val("");}
        }
    }
    else
    {
        document.getElementById("static_status").style.display="none";
        document.getElementById("pppoe_status").style.display="none";
    }
}
function showwifi(){
    show("wifi_setup");
    document.getElementById("wifi_list").innerHTML="";
    if("undefined"!=typeof (configs.wifi_iface) )
    {
        if(configs.wifi_iface.disabled==0)
        {
            if(configs.wifi_iface.mode=='sta')
            {
                document.getElementById("scanbutton").style.visibility="visible";
                document.getElementById("wifi_proto").options[1].selected="true";
                document.getElementById("wifi_ap").style.display="none";
                document.getElementById("wifi_client").style.display="block";

                if(configs.wifi_iface.ssid!="null") {
                    $("#wifi_client_ssid").val(configs.wifi_iface.ssid);
                }else{$("#wifi_client_ssid").val("");}

                if(configs.wifi_iface.key!="null") {
                    $("#wifi_client_pass").val(configs.wifi_iface.key);
                }else{$("#wifi_client_pass").val("");}
            }
            else
            {
                document.getElementById("scanbutton").style.visibility="hidden";
                document.getElementById("wifi_proto").options[0].selected="true";
                document.getElementById("wifi_ap").style.display="block";
                document.getElementById("wifi_client").style.display="none";

                if(configs.wifi_iface.ssid!="null") {
                    $("#wifi_ssid").val(configs.wifi_iface.ssid);
                }else{$("#wifi_ssid").val("");}

                if(configs.wifi_iface.key!="null") {
                    $("#wifi_pass").val(configs.wifi_iface.key);
                }else{$("#wifi_pass").val("");}

                if(configs.wifi_iface.encryption=="psk+auto")
                {
                    document.getElementById("wifi_encrypt").options[0].selected="true";
                }
                if(configs.wifi_iface.encryption=="psk2+auto")
                {
                    document.getElementById("wifi_encrypt").options[1].selected="true";
                }
                if(configs.wifi_iface.encryption=="psk-mixed+auto")
                {
                    document.getElementById("wifi_encrypt").options[2].selected="true";
                }
            }
        }
        else
        {
            //alert("wifi disable0");
            document.getElementById("scanbutton").style.visibility="hidden";
            document.getElementById("wifi_proto").options[2].selected="true";
            document.getElementById("wifi_ap").style.display="none";
            document.getElementById("wifi_client").style.display="none";
        }
    }
    else
    {
      //  alert("wifi disable1");
        document.getElementById("scanbutton").style.visibility="hidden";
        document.getElementById("wifi_proto").options[2].selected="true";
        document.getElementById("wifi_ap").style.display="none";
        document.getElementById("wifi_client").style.display="none";
    }

}
function showhulian(){
    show("hulian_setup");

    document.getElementById("device_1").value=configs.routedif.name1;
    document.getElementById("device_2").value=configs.routedif.name2;
    document.getElementById("device_3").value=configs.routedif.name3;
    document.getElementById("device_4").value=configs.routedif.name4;
    document.getElementById("device_5").value=configs.routedif.name5;
    document.getElementById("device_6").value=configs.routedif.name6;
    document.getElementById("device_7").value=configs.routedif.name7;
    document.getElementById("device_8").value=configs.routedif.name8;
    document.getElementById("device_9").value=configs.routedif.name9;
    document.getElementById("device_10").value=configs.routedif.name10;
    document.getElementById("device_11").value=configs.routedif.name11;
    document.getElementById("device_12").value=configs.routedif.name12;
    document.getElementById("device_13").value=configs.routedif.name13;
    document.getElementById("device_14").value=configs.routedif.name14;
    document.getElementById("device_15").value=configs.routedif.name15;
    document.getElementById("device_16").value=configs.routedif.name16;


    document.getElementById("device_ip1").value=configs.routedif.ip1;
    document.getElementById("device_ip2").value=configs.routedif.ip2;
    document.getElementById("device_ip3").value=configs.routedif.ip3;
    document.getElementById("device_ip4").value=configs.routedif.ip4;
    document.getElementById("device_ip5").value=configs.routedif.ip5;
    document.getElementById("device_ip6").value=configs.routedif.ip6;
    document.getElementById("device_ip7").value=configs.routedif.ip7;
    document.getElementById("device_ip8").value=configs.routedif.ip8;
    document.getElementById("device_ip9").value=configs.routedif.ip9;
    document.getElementById("device_ip10").value=configs.routedif.ip10;
    document.getElementById("device_ip11").value=configs.routedif.ip11;
    document.getElementById("device_ip12").value=configs.routedif.ip12;
    document.getElementById("device_ip13").value=configs.routedif.ip13;
    document.getElementById("device_ip14").value=configs.routedif.ip14;
    document.getElementById("device_ip15").value=configs.routedif.ip15;
    document.getElementById("device_ip16").value=configs.routedif.ip16;


    document.getElementById("device_sport1").value=configs.routedif.sport1;
    document.getElementById("device_sport2").value=configs.routedif.sport2;
    document.getElementById("device_sport3").value=configs.routedif.sport3;
    document.getElementById("device_sport4").value=configs.routedif.sport4;
    document.getElementById("device_sport5").value=configs.routedif.sport5;
    document.getElementById("device_sport6").value=configs.routedif.sport6;
    document.getElementById("device_sport7").value=configs.routedif.sport7;
    document.getElementById("device_sport8").value=configs.routedif.sport8;
    document.getElementById("device_sport9").value=configs.routedif.sport9;
    document.getElementById("device_sport10").value=configs.routedif.sport10;
    document.getElementById("device_sport11").value=configs.routedif.sport11;
    document.getElementById("device_sport12").value=configs.routedif.sport12;
    document.getElementById("device_sport13").value=configs.routedif.sport13;
    document.getElementById("device_sport14").value=configs.routedif.sport14;
    document.getElementById("device_sport15").value=configs.routedif.sport15;
    document.getElementById("device_sport16").value=configs.routedif.sport16;



    document.getElementById("device_dport1").value=configs.routedif.dport1;
    document.getElementById("device_dport2").value=configs.routedif.dport2;
    document.getElementById("device_dport3").value=configs.routedif.dport3;
    document.getElementById("device_dport4").value=configs.routedif.dport4;
    document.getElementById("device_dport5").value=configs.routedif.dport5;
    document.getElementById("device_dport6").value=configs.routedif.dport6;
    document.getElementById("device_dport7").value=configs.routedif.dport7;
    document.getElementById("device_dport8").value=configs.routedif.dport8;
    document.getElementById("device_dport9").value=configs.routedif.dport9;
    document.getElementById("device_dport10").value=configs.routedif.dport10;
    document.getElementById("device_dport11").value=configs.routedif.dport11;
    document.getElementById("device_dport12").value=configs.routedif.dport12;
    document.getElementById("device_dport13").value=configs.routedif.dport13;
    document.getElementById("device_dport14").value=configs.routedif.dport14;
    document.getElementById("device_dport15").value=configs.routedif.dport15;
    document.getElementById("device_dport16").value=configs.routedif.dport16;

    document.getElementById("device_rtspdport1").value=configs.routedif.rtspdport1;
    document.getElementById("device_rtspdport2").value=configs.routedif.rtspdport2;
    document.getElementById("device_rtspdport3").value=configs.routedif.rtspdport3;
    document.getElementById("device_rtspdport4").value=configs.routedif.rtspdport4;
    document.getElementById("device_rtspdport5").value=configs.routedif.rtspdport5;
    document.getElementById("device_rtspdport6").value=configs.routedif.rtspdport6;
    document.getElementById("device_rtspdport7").value=configs.routedif.rtspdport7;
    document.getElementById("device_rtspdport8").value=configs.routedif.rtspdport8;
    document.getElementById("device_rtspdport9").value=configs.routedif.rtspdport9;
    document.getElementById("device_rtspdport10").value=configs.routedif.rtspdport10;
    document.getElementById("device_rtspdport11").value=configs.routedif.rtspdport11;
    document.getElementById("device_rtspdport12").value=configs.routedif.rtspdport12;
    document.getElementById("device_rtspdport13").value=configs.routedif.rtspdport13;
    document.getElementById("device_rtspdport14").value=configs.routedif.rtspdport14;
    document.getElementById("device_rtspdport15").value=configs.routedif.rtspdport15;
    document.getElementById("device_rtspdport16").value=configs.routedif.rtspdport16;

    var items=document.getElementsByName("check_box");
    if(configs.routedif.enable1=="1")
        items[0].checked=true;
    if(configs.routedif.enable2=="1")
        items[1].checked=true;
    if(configs.routedif.enable3=="1")
        items[2].checked=true;
    if(configs.routedif.enable4=="1")
        items[3].checked=true;
    if(configs.routedif.enable5=="1")
        items[4].checked=true;
    if(configs.routedif.enable6=="1")
        items[5].checked=true;
    if(configs.routedif.enable7=="1")
        items[6].checked=true;
    if(configs.routedif.enable8=="1")
        items[7].checked=true;
    if(configs.routedif.enable9=="1")
        items[8].checked=true;
    if(configs.routedif.enable10=="1")
        items[9].checked=true;
    if(configs.routedif.enable11=="1")
        items[10].checked=true;
    if(configs.routedif.enable12=="1")
        items[11].checked=true;
    if(configs.routedif.enable13=="1")
        items[12].checked=true;
    if(configs.routedif.enable14=="1")
        items[13].checked=true;
    if(configs.routedif.enable15=="1")
        items[14].checked=true;
    if(configs.routedif.enable16=="1")
        items[15].checked=true;

    var items2=document.getElementsByName("check_box2");
    if(configs.routedif.rtspenable1=="1")
        items2[0].checked=true;
    if(configs.routedif.rtspenable2=="1")
        items2[1].checked=true;
    if(configs.routedif.rtspenable3=="1")
        items2[2].checked=true;
    if(configs.routedif.rtspenable4=="1")
        items2[3].checked=true;
    if(configs.routedif.rtspenable5=="1")
        items2[4].checked=true;
    if(configs.routedif.rtspenable6=="1")
        items2[5].checked=true;
    if(configs.routedif.rtspenable7=="1")
        items2[6].checked=true;
    if(configs.routedif.rtspenable8=="1")
        items2[7].checked=true;
    if(configs.routedif.rtspenable9=="1")
        items2[8].checked=true;
    if(configs.routedif.rtspenable10=="1")
        items2[9].checked=true;
    if(configs.routedif.rtspenable11=="1")
        items2[10].checked=true;
    if(configs.routedif.rtspenable12=="1")
        items2[11].checked=true;
    if(configs.routedif.rtspenable13=="1")
        items2[12].checked=true;
    if(configs.routedif.rtspenable14=="1")
        items2[13].checked=true;
    if(configs.routedif.rtspenable15=="1")
        items2[14].checked=true;
    if(configs.routedif.rtspenable16=="1")
        items2[15].checked=true;


;


    //for(var i=0;i<items.length;i++){
    //
    //    items[i].checked=true;
    //}


}
function showpass(){
    show("pass_setup");
}
function showserial(){
    show("serial_setup");
    $("#serial_port").val(configs.routedif.serialport);
    switch (configs.routedif.serialrate)
    {
        case "110":
            document.getElementById("serial_rate").options[0].selected="true";
            break;
        case "300":
            document.getElementById("serial_rate").options[1].selected="true";
            break;
        case "1200":
            document.getElementById("serial_rate").options[2].selected="true";
            break;
        case "2400":
            document.getElementById("serial_rate").options[3].selected="true";
            break;
        case "4800":
            document.getElementById("serial_rate").options[4].selected="true";
            break;
        case "9600":
            document.getElementById("serial_rate").options[5].selected="true";
            break;
        case "19200":
            document.getElementById("serial_rate").options[6].selected="true";
            break;
        case "38400":
            document.getElementById("serial_rate").options[7].selected="true";
            break;
        case "57600":
            document.getElementById("serial_rate").options[8].selected="true";
            break;
        case "115200":
            document.getElementById("serial_rate").options[9].selected="true";
            break;
        case "230400":
            document.getElementById("serial_rate").options[10].selected="true";
            break;
        case "256000":
            document.getElementById("serial_rate").options[11].selected="true";
            break;
        default :
            document.getElementById("serial_rate").options[5].selected="true";
    }

    switch (configs.routedif.serialbit)
    {
        case "5":
            document.getElementById("serial_bit").options[0].selected="true";
            break;
        case "6":
            document.getElementById("serial_bit").options[1].selected="true";
            break;
        case "7":
            document.getElementById("serial_bit").options[2].selected="true";
            break;
        case "8":
            document.getElementById("serial_bit").options[3].selected="true";
            break;
        default :
            document.getElementById("serial_bit").options[3].selected="true";
    }

    switch (configs.routedif.serialparity)
    {
        case "NONE":
            document.getElementById("serial_parity").options[0].selected="true";
            break;
        case "ODD":
            document.getElementById("serial_parity").options[1].selected="true";
            break;
        case "EVEN":
            document.getElementById("serial_parity").options[2].selected="true";
            break;
        default :
            document.getElementById("serial_parity").options[0].selected="true";
    }

    switch (configs.routedif.serialstop)
    {
        case "1":
            document.getElementById("serial_stop").options[0].selected="true";
            break;
        case "2":
            document.getElementById("serial_stop").options[1].selected="true";
            break;
        default :
            document.getElementById("serial_stop").options[0].selected="true";
    }
}
function showsimulate(){
    show("simulate_setup");
    document.getElementById("simulate_delay").value=configs.routedif.delay;
    document.getElementById("simulate_loss").value=configs.routedif.loss;
    document.getElementById("simulate_f").value=configs.routedif.fluctuation;


}

function showdirectconnect(){
    show("directconnect_setup");
    if(configs.routedif.vpnproto=="none")
    {
        document.getElementById("vpn_proto").options[0].selected="true";
    }
    if(configs.routedif.vpnproto=="vpnserver")
    {
        document.getElementById("vpn_proto").options[1].selected="true";
    }
    if(configs.routedif.vpnproto=="client")
    {
        document.getElementById("vpn_proto").options[2].selected="true";
    }
    SelectChangevpn();
    $("#vpnserverip").val(configs.routedif.vpnserverip);
    $("#vpnserverport").val(configs.routedif.vpnserverport);

}

function setcookiestatus(data){
    tools.setCookie("loginstatus",data,15000);
}
function getcookiestatus(){
    var a=cookieUtil.get("loginstatus");
    return a;
}
function  _call(req, cb) {
    return $.ajax('/ubus', {
        cache:       false,
        contentType: 'application/json',
        data:        JSON.stringify(req),
        dataType:    'json',
        type:        'POST',
        timeout:     default1.timeout,
        _rpc_req:   req
    }).then(cb, cb);
};

function hidewan(data){
    if(data=="wan")
    {
        document.getElementById("wan_status").style.display="none";
        document.getElementById("wwan_status").style.display="block";
    }
    if(data=="wwan")
    {
        document.getElementById("wwan_status").style.display="none";
        document.getElementById("wan_status").style.display="block";
    }
}

function getId() {
    return id++;
};

function SelectChangewan(){
    var i=document.getElementById("wan_proto").selectedIndex;
    if(i==0)
    {
            document.getElementById("static_status").style.display="block";
            document.getElementById("pppoe_status").style.display="none";
    }
    if(i==1)
    {
        document.getElementById("static_status").style.display="none";
        document.getElementById("pppoe_status").style.display="none";
    }
    if(i==2)
    {
        document.getElementById("static_status").style.display="none";
        document.getElementById("pppoe_status").style.display="block";
    }
}

function SelectChangewifi(){
    document.getElementById("wifi_list").innerHTML="";
    var i=document.getElementById("wifi_proto").selectedIndex;
    if(i==0)
    {
        document.getElementById("scanbutton").style.visibility="hidden";
        document.getElementById("wifi_ap").style.display="block";
        document.getElementById("wifi_client").style.display="none";
    }
    if(i==1)
    {
        document.getElementById("scanbutton").style.visibility="visible";
        document.getElementById("wifi_ap").style.display="none";
        document.getElementById("wifi_client").style.display="block";
    }
    if(i==2)
    {
        document.getElementById("scanbutton").style.visibility="hidden";
        document.getElementById("wifi_ap").style.display="none";
        document.getElementById("wifi_client").style.display="none";
    }
}
function SelectChangevpn(){
    if($("#vpn_proto").val()=="none")
    {
        document.getElementById("vpnip").style.display="none";
        document.getElementById("vpnport").style.display="none";
    }
    if($("#vpn_proto").val()=="vpnserver")
    {
        document.getElementById("vpnip").style.display="none";
        document.getElementById("vpnport").style.display="block";
    }
    if($("#vpn_proto").val()=="vpnclient")
    {
        document.getElementById("vpnip").style.display="block";
        document.getElementById("vpnport").style.display="block";
    }
}

tools = {
    heredoc : function(fn){
        return fn.toString().replace(/\/\*/,'').replace(/\*\//,'').split('\n').slice(1,-1).join('\n') + '\n';
    },
    stopPropagation : function(event){
        if (event.stopPropagation) {
            event.stopPropagation();
        }else if (window.event) {
            window.event.cancelBubble = true;
        }
    },
    setCookie:function(name,valueg,time){
        var exp = new Date();
        exp.setTime(exp.getTime() + time);
        cookieUtil.set(name,valueg,exp.toGMTString());
    },
    toMask:function(num){
        switch (num){
            case 8:
                return '255.0.0.0';
                break;
            case 9:
                return '255.128.0.0';
                break;
            case 10:
                return '255.192.0.0';
                break;
            case 11:
                return '255.224.0.0';
                break;
            case 12:
                return '255.240.0.0';
                break;
            case 13:
                return '255.248.0.0';
                break;
            case 14:
                return '255.252.0.0';
                break;
            case 15:
                return '255.254.0.0';
                break;
            case 16:
                return '255.255.0.0';
                break;
            case 17:
                return '255.255.128.0';
                break;
            case 18:
                return '255.255.192.0';
                break;
            case 19:
                return '255.255.224.0';
                break;
            case 20:
                return '255.255.240.0';
                break;
            case 21:
                return '255.255.248.0';
                break;
            case 22:
                return '255.255.252.0';
                break;
            case 23:
                return '255.255.254.0';
                break;
            case 24:
                return '255.255.255.0';
                break;
            case 25:
                return '255.255.255.128';
                break;
            case 26:
                return '255.255.255.192';
                break;
            case 27:
                return '255.255.255.224';
                break;
            case 28:
                return '255.255.255.240';
                break;
            case 29:
                return '255.255.255.248';
                break;
            case 30:
                return '255.255.255.252';
                break;
            default :
                return '';
                break;
        }
    }
};

cookieUtil = {
    get:function(name){
        var cookieName = encodeURIComponent(name) + "=" ,
            cookieStart = document.cookie.indexOf(cookieName),
            cookieValue = null;
        if(cookieStart > -1){
            var cookieEnd = document.cookie.indexOf(";",cookieStart);
            if(cookieEnd == -1){
                cookieEnd = document.cookie.length;
            }
            cookieValue = decodeURIComponent(document.cookie.substring(cookieStart + cookieName.length, cookieEnd));
        }
        return cookieValue;
    },
    set:function(name, value, expires, path, domain, secure){
        var cookieText = encodeURIComponent(name) + "=" + encodeURIComponent(value);
        if(expires instanceof Date){
            cookieText += ";expires=" + expires.toGMTString();
        }
        if(path){
            cookieText += ";path=" + path;
        }
        if(domain){
            cookieText += ";domain=" + domain;
        }
        if(path){
            cookieText += ";secure=" + secure;
        }
        document.cookie = cookieText;
    },
    unset:function(name, path, domain, secure){
        this.set(name, "" , new Date(0), path, domain, secure);
    },
    checkCookie:function(name){
        var name=get(name);
        if (name!=null && name!=""){
            return name;
        }else{
            return false;
        }
    }
};

function cookieflag(){
    var loginstatus=cookieUtil.get("loginstatus");
    return loginstatus;
};

onClall = {
    _doGetWanMac:function(data){
        if("undefined"==typeof data.result || undefined==typeof data.result) {window.location.href = '../../index.html';}
        else{
          //  alert(data.result[1]);
            configs.wan = data.result[1].values;
            $("#mac").html(configs.wan.macaddr.toUpperCase( ));
        }

    },
    _doGetRoutedif:function(data){
        if("undefined"==typeof data.result || undefined==typeof data.result) {window.location.href = '../../index.html';}
        else{

            configs.routedif = data.result[1].values;
            $("#route_name").html(configs.routedif.name);
            $("#hulian_id").html(configs.routedif.id);

            if(configs.routedif.interconnect =="0")
            {
                $("#hlzts").html('未连接');
            }else if(configs.routedif.interconnect =="1")
            {
                $("#hlzts").html('已连接');
            }



    }

    },
    _dogGetLan:function(data){
        if("undefined"==typeof data.result || undefined==typeof data.result){window.location.href = '../../index.html';}
        else{

            configs.lan = data.result[1].values;
            $("#lan_ip").html(configs.lan.ipaddr);
        }
    },
    _doGetSerial:function(data){
        if(data){
            if("undefined"==typeof data.result || undefined==typeof data.result) {window.location.href = '../../index.html';}
            else{
                     configs.routedif = data.result[1].values;
                    $("#route_name").html(configs.routedif.name);
                    $("#hulian_id").html(configs.routedif.remoteid);
                    if(configs.routedif.interconnect =="0")
                    {
                        $("#hlzts").html('未连接');
                    }else if(configs.routedif.interconnect =="1")
                    {
                        $("#hlzts").html('已连接');
                    }


                if(configs.routedif.vpnproto =="none")
                {
                    $("#directconnect").html('禁用');
                }else if(configs.routedif.vpnproto =="vpnserver")
                {
                    $("#directconnect").html('服务器');
                }else if(configs.routedif.vpnproto =="vpnclient")
                {
                    $("#directconnect").html('客户端');
                }

            }
        }
    },
    _doGetWifiSta:function(data){
        if (data) {

            if ("undefined" == typeof data.result || undefined == typeof data.result)
            {
                window.location.href = '../../index.html';
            }
            else
            {
                configs.wifi_iface = data.result[1].values;
                //configs.wifi_iface.disabled = configs.disabled = data.result[1].values.disabled == undefined || data.result[1].values.disabled == 0 || data.result[1].values.disabled == "0" ? 0 : 1;
                configs.encryption = data.result[1].values.encryption;
                configs.ssid = data.result[1].values.ssid;

                $("#ssid").html(configs.ssid);
                $("#wifi_passwd").html(configs.wifi_iface.key);
                if (configs.wifi_iface.disabled == 0) {
                    if (configs.wifi_iface.mode == 'sta') {
                        $("#wifi_status").html('客户端(client)');
                        hidewan("wan");
                        $("#wan_state").html('由Wifi接入Internet（dhcp）');

                    }
                    else {
                        $("#wifi_status").html('无线访问点(AP)');
                        hidewan("wwan");
                    }
                }
                else {
                    $("#wifi_status").html('关闭');
                }
            }
        }
    },
    _doGetWanStatus:function(data) {
        if(configs.wifi_iface.disabled==0&&configs.wifi_iface.mode=='sta')
        {
            return;
        }
        hidewan("wwan");

        if("undefined"==typeof data.result || undefined==typeof data.result){}
        else{

            if (data.result[1].proto == "static") {
                $("#wan_state").html("静态地址");
            }
            if (data.result[1].proto == "dhcp") {
                $("#wan_state").html("动态获取(DHCP)");
            }
            if (data.result[1].proto == "pppoe") {
                $("#wan_state").html("PPPOE拨号");
            }

            if (data.result[1].up == true)
            {
                var result = data.result[1];
                configs.wanStauts = {
                    up: data.result[1].up,
                    proto: result.proto,
                    gateway: result.route[0].nexthop,
                    ipaddr: result["ipv4-address"][0].address,
                    netmask: tools.toMask(result["ipv4-address"][0].mask)
                };
                configs.wanStauts.dns = [];

                if (result["dns-server"][0] !== undefined)
                {
                    configs.wanStauts.dns[0] = result["dns-server"][0];
                }
                else
                {
                    configs.wanStauts.dns[0] = 'null';
                }

                if (result["dns-server"][1] !== undefined)
                {
                    configs.wanStauts.dns[1] = result["dns-server"][1];
                }
                else
                {
                    configs.wanStauts.dns[1] = 'null';
                }
            }
            else {
                configs.wanStauts = {
                    up: false,
                    proto: data.result[1].proto,
                    gateway: '',
                    ipaddr: '',
                    netmask: '',
                    dns: ['', '']
                };
            }
            $("#wan_ip").html(configs.wanStauts.ipaddr);
            $("#wan_mask").html(configs.wanStauts.netmask);
            $("#wan_gateway").html(configs.wanStauts.gateway);
            $("#wan_dns1").html(configs.wanStauts.dns[0]);
            $("#wan_dns2").html(configs.wanStauts.dns[1]);
        }
    },

    _doGetWwanStatus:function(data) {
        configs.WwanStauts = {
            up: false,
            proto: '',
            gateway: '',
            ipaddr: '',
            netmask: '',
            dns: ['', '']
        };
        if("undefined"==typeof data.result || undefined==typeof data.result){

        }
        else
        {
            if (data.result[1].up == true)
            {
                var result = data.result[1];
                configs.WwanStauts = {
                    up: true,
                    proto: result.proto,
                    gateway: result.route[0].nexthop,
                    ipaddr: result["ipv4-address"][0].address,
                    netmask: tools.toMask(result["ipv4-address"][0].mask)
                };
            }
        }
        $("#wwan_ip").html(configs.WwanStauts.ipaddr);
        $("#wwan_gateway").html(configs.WwanStauts.gateway);
    },
    _doCommitNetwork:function(){
        var reg =
        {
            id: getId(),
            jsonrpc:'2.0',
            method:"call",
            params:[option.sid,'uci','commit',{config:'network'}]
        };
        _call(reg,function(data){
            var lists = [
                onReadre.list.WlanStatus
            ];
           // onReadre.get(lists);
        });
    },
    _doCommitWireless:function(){

        var reg =
        {
            id: getId(),
            jsonrpc:'2.0',
            method:"call",
            params:[option.sid,'uci','commit',{config:'wireless'}]
        };
        _call(reg,function(data){
            var lists = [
                onReadre.list.wifi
            ];
          //  S.onReadre.get(lists);
        });
    },

    _doScanWifi:function(data){
        if(data){
            var list = configs.wifi_List = data.result[1].results;
            var str = '';
            str +='<div style="border-bottom: 1px groove;"><span>序号</span><span style="margin-left: 15px">无线SSID</span><span style="margin-left: 350px">信号强度</span></div>';
            for(var i in list){
                str += '<div style="width: 100%;height:32px;border-bottom: 1px groove;line-height: 32px;overflow: hidden;">'


                //if((typeof (list[i].bssid) != undefined) && (typeof (list[i].bssid) != "undefined") && (typeof (list[i].bssid) != null)){
                //    str += '<span style="display: block;float: left;width: 200px;">&nbsp;&nbsp;'+list[i].bssid+'</span>';
                //}
                str += '<span style="display: block;float: left;width: 480px;">'+i+'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'+list[i].ssid+'</span>';


                if(list[i].signal>=-50)
                { str += '<span style="width: 50px;height: 50px;overflow:hidden;background: url(signal.png) no-repeat -163px -5px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp</span>';}
                else if(list[i].signal>=-60){str += '<span style="width: 50px;height: 50px;overflow:hidden;background: url(signal.png) no-repeat -122px -5px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp</span>';}
                else if(list[i].signal>=-70){str += '<span style="width: 50px;height: 50px;overflow:hidden;background: url(signal.png) no-repeat -81px -5px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp</span>';}
                else if(list[i].signal>=-80){str += '<span style="width: 50px;height: 50px;overflow:hidden;background: url(signal.png) no-repeat -42px -5px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp</span>';}
                else {str += '<span style="width: 50px;height: 50px;overflow:hidden;background: url(signal.png) no-repeat -4px -5px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp</span>';}


                str += '<span style="float:right;"><button  no="'+i+'" class="add_wifi_set" >加入网路</button></span>';
                str += '</div> ';
            }
            $("#wifi_list").html(str);
         regEvent.doaddwificlient();
        }
    },

    _doCommitHulian:function(){
        var reg =
        {
            id:getId(),
            jsonrpc:'2.0',
            method:"call",
            params:[option.sid,'uci','commit',{config:'routedif'}]
        };
        _call(reg,function(data){});
    }

};

function loginverify() {
    var staticuser = $('#username').val();
    var staticpass = $("#password").val();
    var val=false;
    var reg =
    {
        id: getId(),
        jsonrpc:'2.0',
        method:"call",
        params:[ '00000000000000000000000000000000','session','login',{username:staticuser,password:staticpass}]
    };
    $.ajax('/ubus', {
        cache:       false,
        contentType: 'application/json',
        data:        JSON.stringify(reg),
        dataType:    'json',
        type:        'POST',
        timeout:     default1.timeout,
        _rpc_req:   reg,
        error:function(){
            alert("登录失败");
        },
        async:false,
        success:function(data)
        {
            if(data)
            {
                if(typeof data.result != undefined && typeof data.result != "undefined"){
                    if(data.result[0] == 0)
                    {
                        tools.setCookie('isLogin', 1);
                        var returndata = data.result[1];
                        option.sid = returndata.ubus_rpc_session;
                        option.isLogin = true;
                        tools.setCookie('sid',returndata.ubus_rpc_session,option.timeout);
                        tools.setCookie("sid",option.sid,15000);
                        val=true;
                    }
                    else
                    {
                        window.location.reload(true);
                        alert("登录失败");
                    }
                }
                else
                {
                    window.location.reload(true);
                    alert("登录失败");
                }
            }
            else
            {
                window.location.reload(true);
                alert("登录失败");
            }
        }
    });
    return val;
};

$(document).ready(function(){
    $("#loginbtn").click(function(){
        var a=loginverify();
        if(a==true){
            setcookiestatus("1");
            window.location.href='setup.html';
        }else
        {
            setcookiestatus("0");
        }
    });

    $("#bar_status").click(function(){
        if(clickbutton=="bar_status"){return;}
        clickbutton="bar_status";
       showstatus();
    });

    $("#bar_setup").click(function(){
        if(clickbutton=="bar_setup"){return;}
       clickbutton="bar_setup";
        showsetup();
    });

    $("#bar_wifi").click(function(){
        if(clickbutton=="bar_wifi"){return;}
        showwifi();
        clickbutton="bar_wifi";
    });

    $("#bar_hulian").click(function(){
        clickbutton="bar_hulian";
        showhulian();
    });

    $("#bar_pass").click(function(){
        clickbutton="bar_pass";
        showpass();
    });

    $("#bar_serial").click(function(){
        clickbutton="bar_serial";
        showserial();
    });

    $("#bar_simulate").click(function(){
        clickbutton="bar_simulate";
        showsimulate();
    });

    $("#bar_directconnect").click(function(){
        clickbutton="bar_directconnect";
        showdirectconnect();
    });

    $("#bar_quit").click(function(){
        onReadre.logout();
    });

    $("#settingbutton").click(function(){
        onReadre.setNet();
        onReadre.init();//更新一次参数
    });

    $("#wifibutton").click(function(){
        onReadre.setWifi();
        onReadre.init();//更新一次参数
    });

    $("#scanbutton").click(function(){

        if(configs.wifi_iface.disabled==1)
        {
            alert("无线没有启用，可以先保存一次为客户端后再扫描");
            return;
        }
        var lists = [
            onReadre.list.scanWifi
        ];
        onReadre.get(lists);
        onReadre.init();//更新一次参数
    });

    $('#hulianbutton').click(function() {
        onReadre.setHulian();
        onReadre.init();//更新一次参数
    });

    $('#passbutton').click(function() {
        onReadre.setpass();
        onReadre.logout();
    });

    $('.rebootbutton').click(function() {
        onReadre.reboot();
        onReadre.logout();
    });


    $('#serialbutton').click(function() {
        var port =  $('#serial_port').val();
        var rate =  $('#serial_rate').val();
        var bit= $('#serial_bit').val();
        var parity= $('#serial_parity').val();
        var stop= $('#serial_stop').val();
        if (port == "")
            port = "2323";
        var lists = [];
        var params = {};
        var params = onReadre.list.hulian;
        params.params[3].values = {};
        params.params[3].values = {"serialport":port,"serialrate":rate,"serialbit":bit,"serialparity":parity,"serialstop":stop};
        lists[0] = params;
        onReadre.set(lists);
        onReadre.init();//更新一次参数
    });


    $('#simulatebutton').click(function() {
        var delay =  $('#simulate_delay').val();
        var f =  $('#simulate_f').val();
        var loss= $('#simulate_loss').val();
        if (delay == "")
            delay = "0";
        if (f == "")
            f = "0";
        if (loss == "")
            loss = "0";


        var lists = [];
        var params = {};
        var params = onReadre.list.hulian;
        params.params[3].values = {};
        params.params[3].values = {"delay":delay,"fluctuation":f,"loss":loss};
        lists[0] = params;
        onReadre.set(lists);
        onReadre.init();//更新一次参数
    });


    $('#directconnectbutton').click(function() {
        var proto =  $('#vpn_proto').val();
        var ip =  $('#vpnserverip').val();
        var port= $('#vpnserverport').val();
        if (ip == "")
            f = "192.168.1.2";
        if (port == "")
            port = "2222";

        var lists = [];
        var params = {};
        var params = onReadre.list.hulian;
        params.params[3].values = {};
        params.params[3].values = {"vpnproto":proto,"vpnserverip":ip,"vpnserverport":port};
        lists[0] = params;
        onReadre.set(lists);
        onReadre.init();//更新一次参数
    });


});
regEvent = {
    doaddwificlient: function () {
        $(".add_wifi_set").click(function(){
            var no = $(this).attr("no");
            document.getElementById("wifi_client_ssid").value=configs.wifi_List[no].ssid;
        });
    }
}

onReadre = {
    index:0,
    sid:null,
    list:{
        reboot:{
            params:['0','luci2.system','reboot','{}']
        },
        restart:{
            params:['0','luci2.system','init_action',{name:"",action:""}]
        },
        lan:{
            params:['0','uci','get',{config:'network',section:'lan'}],
            callback: onClall._dogGetLan
        },
        wanmac:{
            params:['0','uci','get',{config:'network',section:'wan'}],
            callback: onClall._doGetWanMac
        },
        serial:{
            params:['0','uci','get',{config:'routedif',section:'@routedif[0]'}],
            callback: onClall._doGetSerial
        },
        wifi:{
            params:['0','uci','get',{config:'wireless',section:'@wifi-iface[0]'}],
            callback: onClall._doGetWifiSta
        },
        WwanStatus:{
            params:['0','network.interface.wwan','status',{}],
            callback: onClall._doGetWwanStatus
        },
        WanStatus:{
            params:['0','network.interface.wan','status',{}],
            callback: onClall._doGetWanStatus
        },
        commit_wan_dhcp:{
            params:['0','uci','set',{config:'network',section:'wan'}],
            callback: onClall._doCommitNetwork
        },
        delte_network_option:{
            params:['0','uci','delete',{config:'network',section:'wan'}]
        },
        setWifiConfig:{
            params:['0','uci','set',{config:'wireless',section:'@wifi-iface[0]'}],
            callback: onClall._doCommitWireless
        },
        scanWifi:{
            //ubus call iwinfo scan '{"device":"wlan0"}'
            params:['0','iwinfo','scan',{"device":'wlan0'}],
            callback: onClall._doScanWifi
        },
        hulian:{
            params:['0','uci','set',{config:'routedif',section:'@routedif[0]'}],
            callback: onClall._doCommitHulian
        },

        commit_lan:{
            params:['0','uci','set',{config:'network',section:'lan'}],
            callback: onClall._doCommitHulian
        },
        get_device:{
            //params:['0','uci','get',{config:'routedif',section:'@routedif[0]'}],
            params:['0','uci','get',{config:'routedif',section:'@routedif[0]'}],
            callback: onClall._doGetRoutedif
        }

    },
    get:function(list){
        var b=cookieUtil.get("sid");
        option.sid=b;

        if(list.length>0){
            var regs =[];
            for(var ii=0;ii<list.length;ii++){
                var tmpid=getId();
                if(list[ii].params[0] == '0') { list[ii].params[0] = option.sid;}
                regs.push({
                    id: tmpid,
                    jsonrpc:'2.0',
                    method:"call",
                    params:list[ii].params
                });
            }
            _call(regs,function(data){
                if(data){
                    for(var i=0;i<data.length;i++){
                        if(typeof (list[i].callback) != "undefined" && list[i].callback != undefined){
                            list[i].callback(data[i]);
                        }
                    }
                }
            });
        }
    },

    init:function(){
        var lists = [

            this.list.lan,
           // this.list.hulian,
            this.list.wifi,

         //   this.list.serial,

            this.list.wanmac,
            this.list.WwanStatus,
            this.list.WanStatus,
            this.list.get_device

        ];
        this.get(lists);
    },

    setNet:function(){
        var lists2 = [];
        var lanip= $("#lan_ip1").val();
        var params2 = onReadre.list.commit_lan;
        params2.params[3].values = {};
        params2.params[3].values = {"ipaddr":lanip};
        lists2[0] = params2;
        onReadre.set(lists2);


        var lists = [];
        var proto = $("#wan_proto").val();

        var params = {};
        params = this.list.commit_wan_dhcp;
        switch (proto){
            case 'dhcp':
                params.params[3].values = {};
                params.params[3].values = {proto:'dhcp'};
                lists[0] = params;
                break;
            case 'static':
                var ip = $("#wan_static_ip").val();
                var netmasks = $("#wan_static_mask").val();
                var gateway = $("#wan_static_gateway").val();
                var dns1 = $("#wan_static_dns1").val();
                var dns2 = $("#wan_static_dns2").val();
                params.params[3].values = {};
                params.params[3].values = {proto:'static',ipaddr:ip,netmask:netmasks,gateway:gateway,dns:[dns1,dns2]};
                lists[0] = params;
                break;
            case 'pppoe':
                var name = $("#pppoe_user").val();
                var pass = $("#pppoe_pass").val();
                params.params[3].values = {};
                params.params[3].values = {proto:'pppoe',username:name,password:pass};
                lists[0] = params;
                break
        }
        onReadre.set(lists);
    },

    setWifi:function(){
        var type=document.getElementById("wifi_proto").selectedIndex;
        if( type== 0){ //ap
            var i=document.getElementById("wifi_encrypt").selectedIndex;
            var encrypt="psk+mixed+auto";
            if(i==0){encrypt="psk+auto"};
            if(i==1){encrypt="psk2+auto"};
            if(i==2){encrypt="psk-mixed+auto"};
            var ssid =  $("#wifi_ssid").val();
            var key =  $("#wifi_pass").val();
            var lists = [];
            var params = {};
            var params = this.list.setWifiConfig;
            params.params[3].values = {};
            params.params[3].values = {"disabled":0,"mode":"ap","encryption":encrypt,"ssid":ssid,"key":key,'network':'lan'};
            lists[0] = params;
            onReadre.set(lists);
        }
        else if(type == "1")
        {//sta
            var ssid =  $("#wifi_client_ssid").val();
            var key =  $("#wifi_client_pass").val();
            var lists = [];
            var params = {};
            var params = this.list.setWifiConfig;
            params.params[3].values = {};
            params.params[3].values = {"disabled":0,"ssid":ssid,"encryption":"psk-mixed+auto","network":"wwan","key":key,"mode":"sta"};
            lists[0] = params;
            onReadre.set(lists);
        }else if(type == "2")
        {
            var lists = [];
            var params = {};
            var params = this.list.setWifiConfig;
            params.params[3].values = {};
            params.params[3].values = {"disabled":"1"};
            lists[0] = params;
            onReadre.set(lists);
        }
    },

    set:function(list){
        var b=cookieUtil.get("sid");
        option.sid=b;

        if(list.length>0){
            var regs =[];
            for(var ii=0;ii<list.length;ii++){
                if(list[ii].params[0] == '0') list[ii].params[0] = option.sid;
                regs.push({
                    id: getId(),
                    jsonrpc:'2.0',
                    method:"call",
                    params:list[ii].params
                });
            }
            _call(regs,function(data){
                if(data){
                    for(var i=0;i<data.length;i++){
                        if(typeof (list[i].callback) != "undefined" && list[i].callback != undefined){
                            list[i].callback(data[i]);
                        }
                    }
                }
            });
        }
    },

    setHulian:function(){

        var name =[];
        var ip=[];
        var sport=[];
        var dport=[];
        var rtspdport=[];
        var enable=[];
        var enable2=[];
        name[0]= $('#device_1').val();
        name[1]= $('#device_2').val();
        name[2]= $('#device_3').val();
        name[3]= $('#device_4').val();
        name[4]= $('#device_5').val();
        name[5]= $('#device_6').val();
        name[6]= $('#device_7').val();
        name[7]= $('#device_8').val();
        name[8]= $('#device_9').val();
        name[9]= $('#device_10').val();
        name[10]= $('#device_11').val();
        name[11]= $('#device_12').val();
        name[12]= $('#device_13').val();
        name[13]= $('#device_14').val();
        name[14]= $('#device_15').val();
        name[15]= $('#device_16').val();

        ip[0]= $('#device_ip1').val();
        ip[1]= $('#device_ip2').val();
        ip[2]= $('#device_ip3').val();
        ip[3]= $('#device_ip4').val();
        ip[4]= $('#device_ip5').val();
        ip[5]= $('#device_ip6').val();
        ip[6]= $('#device_ip7').val();
        ip[7]= $('#device_ip8').val();
        ip[8]= $('#device_ip9').val();
        ip[9]= $('#device_ip10').val();
        ip[10]= $('#device_ip11').val();
        ip[11]= $('#device_ip12').val();
        ip[12]= $('#device_ip13').val();
        ip[13]= $('#device_ip14').val();
        ip[14]= $('#device_ip15').val();
        ip[15]= $('#device_ip16').val();


        sport[0]= $('#device_sport1').val();
        sport[1]= $('#device_sport2').val();
        sport[2]= $('#device_sport3').val();
        sport[3]= $('#device_sport4').val();
        sport[4]= $('#device_sport5').val();
        sport[5]= $('#device_sport6').val();
        sport[6]= $('#device_sport7').val();
        sport[7]= $('#device_sport8').val();
        sport[8]= $('#device_sport9').val();
        sport[9]= $('#device_sport10').val();
        sport[10]= $('#device_sport11').val();
        sport[11]= $('#device_sport12').val();
        sport[12]= $('#device_sport13').val();
        sport[13]= $('#device_sport14').val();
        sport[14]= $('#device_sport15').val();
        sport[15]= $('#device_sport16').val();


        dport[0]= $('#device_dport1').val();
        dport[1]= $('#device_dport2').val();
        dport[2]= $('#device_dport3').val();
        dport[3]= $('#device_dport4').val();
        dport[4]= $('#device_dport5').val();
        dport[5]= $('#device_dport6').val();
        dport[6]= $('#device_dport7').val();
        dport[7]= $('#device_dport8').val();
        dport[8]= $('#device_dport9').val();
        dport[9]= $('#device_dport10').val();
        dport[10]= $('#device_dport11').val();
        dport[11]= $('#device_dport12').val();
        dport[12]= $('#device_dport13').val();
        dport[13]= $('#device_dport14').val();
        dport[14]= $('#device_dport15').val();
        dport[15]= $('#device_dport16').val();


        rtspdport[0]= $('#device_rtspdport1').val();
        rtspdport[1]= $('#device_rtspdport2').val();
        rtspdport[2]= $('#device_rtspdport3').val();
        rtspdport[3]= $('#device_rtspdport4').val();
        rtspdport[4]= $('#device_rtspdport5').val();
        rtspdport[5]= $('#device_rtspdport6').val();
        rtspdport[6]= $('#device_rtspdport7').val();
        rtspdport[7]= $('#device_rtspdport8').val();
        rtspdport[8]= $('#device_rtspdport9').val();
        rtspdport[9]= $('#device_rtspdport10').val();
        rtspdport[10]= $('#device_rtspdport11').val();
        rtspdport[11]= $('#device_rtspdport12').val();
        rtspdport[12]= $('#device_rtspdport13').val();
        rtspdport[13]= $('#device_rtspdport14').val();
        rtspdport[14]= $('#device_rtspdport15').val();
        rtspdport[15]= $('#device_rtspdport16').val();

        var items=document.getElementsByName("check_box");
        var items2=document.getElementsByName("check_box2");

        for(var i=0;i<16;i++)
        {
            if(items[i].checked)
                enable[i]=1;
            else
                enable[i]=0
        }

        for(var i=0;i<16;i++)
        {
            if(items2[i].checked)
                enable2[i]=1;
            else
                enable2[i]=0
        }

        var lists = [];
        var params = {};
        var params = this.list.hulian;
        params.params[3].values = {};
        params.params[3].values = {"name1":name[0],"name2":name[1],"name3":name[2],"name4":name[3],"name5":name[4],"name6":name[5],"name7":name[6],"name8":name[7],"name9":name[8],"name10":name[9],"name11":name[10],"name12":name[11],"name13":name[12],"name14":name[13],"name15":name[14],"name16":name[15],
            "ip1":ip[0],"ip2":ip[1],"ip3":ip[2],"ip4":ip[3],"ip5":ip[4],"ip6":ip[5],"ip7":ip[6],"ip8":ip[7],"ip9":ip[8],"ip10":ip[9],"ip11":ip[10],"ip12":ip[11],"ip13":ip[12],"ip14":ip[13],"ip15":ip[14],"ip16":ip[15],
            "sport1":sport[0],"sport2":sport[1],"sport3":sport[2],"sport4":sport[3],"sport5":sport[4],"sport6":sport[5],"sport7":sport[6],"sport8":sport[7],"sport9":sport[8],"sport10":sport[9],"sport11":sport[10],"sport12":sport[11],"sport13":sport[12],"sport14":sport[13],"sport15":sport[14],"sport16":sport[15],
            "dport1":dport[0],"dport2":dport[1],"dport3":dport[2],"dport4":dport[3],"dport5":dport[4],"dport6":dport[5],"dport7":dport[6],"dport8":dport[7],"dport9":dport[8],"dport10":dport[9],"dport11":dport[10],"dport12":dport[11],"dport13":dport[12],"dport14":dport[13],"dport15":dport[14],"dport16":dport[15],
            "rtspdport1":rtspdport[0],"rtspdport2":rtspdport[1],"rtspdport3":rtspdport[2],"rtspdport4":rtspdport[3],"rtspdport5":rtspdport[4],"rtspdport6":rtspdport[5],"rtspdport7":rtspdport[6],"rtspdport8":rtspdport[7],"rtspdport9":rtspdport[8],"rtspdport10":rtspdport[9],"rtspdport11":rtspdport[10],"rtspdport12":rtspdport[11],"rtspdport13":rtspdport[12],"rtspdport14":rtspdport[13],"rtspdport15":rtspdport[14],"rtspdport16":rtspdport[15],
            "rtspenable1":enable2[0],"rtspenable2":enable2[1],"rtspenable3":enable2[2],"rtspenable4":enable2[3],"rtspenable5":enable2[4],"rtspenable6":enable2[5],"rtspenable7":enable2[6],"rtspenable8":enable2[7],"rtspenable9":enable2[8],"rtspenable10":enable2[9],"rtspenable11":enable2[10],"rtspenable12":enable2[11],"rtspenable13":enable2[12],"rtspenable14":enable2[13],"rtspenable15":enable2[14],"rtspenable16":enable2[15],
            "enable1":enable[0],"enable2":enable[1],"enable3":enable[2],"enable4":enable[3],"enable5":enable[4],"enable6":enable[5],"enable7":enable[6],"enable8":enable[7],"enable9":enable[8],"enable10":enable[9],"enable11":enable[10],"enable12":enable[11],"enable13":enable[12],"enable14":enable[13],"enable15":enable[14],"enable16":enable[15]};
        lists[0] = params;
        onReadre.set(lists);
    },

    setpass:function(){
        var pass1= $.trim($("#pass1").val());
        var pass2 = $.trim($("#pass2").val());
        if(pass1 !="" && pass1.length >0){
            if(pass1 != pass2){
                alert("两次密码不一致，请重新设置");
                return;
            }
            var reg ={
                id: getId(),
                jsonrpc:'2.0',
                method:"call",
                params:[option.sid,'luci2.system','password_set',{user: "admin",password:pass1}]
            };
            _call(reg,function(data){});
        }else{
            alert("密码错误");
            return;
        }
    },

    logout:function(){
        var reg ={
            id: getId(),
            jsonrpc:'2.0',
            method:"call",
            params:[option.sid,'session','destroy',{session: option.sid}]
        };
        _call(reg,function(data){});
        option = {};
        cookieUtil.unset('sid');
        location.reload(true);
    },

    reboot:function(){
        var reg ={
            id: getId(),
            jsonrpc:'2.0',
            method:"call",
            params:[option.sid,'luci2.system','reboot',{}]
        };
        _call(reg,function(data){
        });
    }


};